﻿using System;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.ExpressApp.Web;
using System.Collections.Generic;
using DevExpress.ExpressApp.Xpo;

namespace aztall.Web {
    // For more typical usage scenarios, be sure to check out https://documentation.devexpress.com/eXpressAppFramework/DevExpressExpressAppWebWebApplicationMembersTopicAll.aspx
    public partial class aztallAspNetApplication : WebApplication {
        private DevExpress.ExpressApp.SystemModule.SystemModule module1;
        private DevExpress.ExpressApp.Web.SystemModule.SystemAspNetModule module2;
        private aztall.Module.aztallModule module3;
        private aztall.Module.Web.aztallAspNetModule module4;
        private DevExpress.ExpressApp.Security.SecurityModule securityModule1;
        private DevExpress.ExpressApp.Security.SecurityStrategyComplex securityStrategyComplex1;
        private DevExpress.ExpressApp.Security.AuthenticationStandard authenticationStandard1;
        private DevExpress.ExpressApp.AuditTrail.AuditTrailModule auditTrailModule;
        private DevExpress.ExpressApp.Objects.BusinessClassLibraryCustomizationModule objectsModule;
        private DevExpress.ExpressApp.Chart.ChartModule chartModule;
        private DevExpress.ExpressApp.Chart.Web.ChartAspNetModule chartAspNetModule;
        private DevExpress.ExpressApp.CloneObject.CloneObjectModule cloneObjectModule;
        private DevExpress.ExpressApp.ConditionalAppearance.ConditionalAppearanceModule conditionalAppearanceModule;
        private DevExpress.ExpressApp.FileAttachments.Web.FileAttachmentsAspNetModule fileAttachmentsAspNetModule;
        private DevExpress.ExpressApp.Kpi.KpiModule kpiModule;
        private DevExpress.ExpressApp.Notifications.NotificationsModule notificationsModule;
        private DevExpress.ExpressApp.Notifications.Web.NotificationsAspNetModule notificationsAspNetModule;
        private DevExpress.ExpressApp.PivotChart.PivotChartModuleBase pivotChartModuleBase;
        private DevExpress.ExpressApp.PivotChart.Web.PivotChartAspNetModule pivotChartAspNetModule;
        private DevExpress.ExpressApp.PivotGrid.PivotGridModule pivotGridModule;
        private DevExpress.ExpressApp.PivotGrid.Web.PivotGridAspNetModule pivotGridAspNetModule;
        private DevExpress.ExpressApp.ReportsV2.ReportsModuleV2 reportsModuleV2;
        private DevExpress.ExpressApp.ReportsV2.Web.ReportsAspNetModuleV2 reportsAspNetModuleV2;
        private DevExpress.ExpressApp.Scheduler.SchedulerModuleBase schedulerModuleBase;
        private DevExpress.ExpressApp.Scheduler.Web.SchedulerAspNetModule schedulerAspNetModule;
        private DevExpress.ExpressApp.StateMachine.StateMachineModule stateMachineModule;
        private DevExpress.ExpressApp.TreeListEditors.TreeListEditorsModuleBase treeListEditorsModuleBase;
        private DevExpress.ExpressApp.TreeListEditors.Web.TreeListEditorsAspNetModule treeListEditorsAspNetModule;
        private DevExpress.ExpressApp.Validation.ValidationModule validationModule;
        private DevExpress.ExpressApp.Validation.Web.ValidationAspNetModule validationAspNetModule;
        private DevExpress.ExpressApp.ViewVariantsModule.ViewVariantsModule viewVariantsModule;
        private DevExpress.ExpressApp.Workflow.WorkflowModule workflowModule;

        public aztallAspNetApplication() {
            InitializeComponent();
            LinkNewObjectToParentImmediately = false;
        }
        protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
            CreateXPObjectSpaceProvider(args.ConnectionString, args);
            args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null));
        }
        private void CreateXPObjectSpaceProvider(string connectionString, CreateCustomObjectSpaceProviderEventArgs e) {
            System.Web.HttpApplicationState application = (System.Web.HttpContext.Current != null) ? System.Web.HttpContext.Current.Application : null;
            IXpoDataStoreProvider dataStoreProvider = null;
            if(application != null && application["DataStoreProvider"] != null) {
                dataStoreProvider = application["DataStoreProvider"] as IXpoDataStoreProvider;
                e.ObjectSpaceProviders.Add(new XPObjectSpaceProvider(dataStoreProvider, true));
            }
            else {
                if(!String.IsNullOrEmpty(connectionString)) {
                    connectionString = DevExpress.Xpo.XpoDefault.GetConnectionPoolString(connectionString);
                    dataStoreProvider = new ConnectionStringDataStoreProvider(connectionString, true);
                }
                else if(e.Connection != null) {
                    dataStoreProvider = new ConnectionDataStoreProvider(e.Connection);
                }
                if (application != null) {
                    application["DataStoreProvider"] = dataStoreProvider;
                }
                e.ObjectSpaceProviders.Add(new XPObjectSpaceProvider(dataStoreProvider, true));
            }
        }
        private void aztallAspNetApplication_DatabaseVersionMismatch(object sender, DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs e) {
#if EASYTEST
            e.Updater.Update();
            e.Handled = true;
#else
            if(System.Diagnostics.Debugger.IsAttached) {
                e.Updater.Update();
                e.Handled = true;
            }
            else {
				string message = "The application cannot connect to the specified database, " +
					"because the database doesn't exist, its version is older " +
					"than that of the application or its schema does not match " +
					"the ORM data model structure. To avoid this error, use one " +
					"of the solutions from the https://www.devexpress.com/kb=T367835 KB Article.";

                if(e.CompatibilityError != null && e.CompatibilityError.Exception != null) {
                    message += "\r\n\r\nInner exception: " + e.CompatibilityError.Exception.Message;
                }
                throw new InvalidOperationException(message);
            }
#endif
        }
        private void InitializeComponent() {
			this.module1 = new DevExpress.ExpressApp.SystemModule.SystemModule();
			this.module2 = new DevExpress.ExpressApp.Web.SystemModule.SystemAspNetModule();
			this.module3 = new aztall.Module.aztallModule();
			this.module4 = new aztall.Module.Web.aztallAspNetModule();
			this.securityModule1 = new DevExpress.ExpressApp.Security.SecurityModule();
			this.securityStrategyComplex1 = new DevExpress.ExpressApp.Security.SecurityStrategyComplex();
			this.authenticationStandard1 = new DevExpress.ExpressApp.Security.AuthenticationStandard();
			this.auditTrailModule = new DevExpress.ExpressApp.AuditTrail.AuditTrailModule();
			this.objectsModule = new DevExpress.ExpressApp.Objects.BusinessClassLibraryCustomizationModule();
			this.chartModule = new DevExpress.ExpressApp.Chart.ChartModule();
			this.chartAspNetModule = new DevExpress.ExpressApp.Chart.Web.ChartAspNetModule();
			this.cloneObjectModule = new DevExpress.ExpressApp.CloneObject.CloneObjectModule();
			this.conditionalAppearanceModule = new DevExpress.ExpressApp.ConditionalAppearance.ConditionalAppearanceModule();
			this.fileAttachmentsAspNetModule = new DevExpress.ExpressApp.FileAttachments.Web.FileAttachmentsAspNetModule();
			this.kpiModule = new DevExpress.ExpressApp.Kpi.KpiModule();
			this.notificationsModule = new DevExpress.ExpressApp.Notifications.NotificationsModule();
			this.notificationsAspNetModule = new DevExpress.ExpressApp.Notifications.Web.NotificationsAspNetModule();
			this.pivotChartModuleBase = new DevExpress.ExpressApp.PivotChart.PivotChartModuleBase();
			this.pivotChartAspNetModule = new DevExpress.ExpressApp.PivotChart.Web.PivotChartAspNetModule();
			this.pivotGridModule = new DevExpress.ExpressApp.PivotGrid.PivotGridModule();
			this.pivotGridAspNetModule = new DevExpress.ExpressApp.PivotGrid.Web.PivotGridAspNetModule();
			this.reportsModuleV2 = new DevExpress.ExpressApp.ReportsV2.ReportsModuleV2();
			this.reportsAspNetModuleV2 = new DevExpress.ExpressApp.ReportsV2.Web.ReportsAspNetModuleV2();
			this.schedulerModuleBase = new DevExpress.ExpressApp.Scheduler.SchedulerModuleBase();
			this.schedulerAspNetModule = new DevExpress.ExpressApp.Scheduler.Web.SchedulerAspNetModule();
			this.stateMachineModule = new DevExpress.ExpressApp.StateMachine.StateMachineModule();
			this.treeListEditorsModuleBase = new DevExpress.ExpressApp.TreeListEditors.TreeListEditorsModuleBase();
			this.treeListEditorsAspNetModule = new DevExpress.ExpressApp.TreeListEditors.Web.TreeListEditorsAspNetModule();
			this.validationModule = new DevExpress.ExpressApp.Validation.ValidationModule();
			this.validationAspNetModule = new DevExpress.ExpressApp.Validation.Web.ValidationAspNetModule();
			this.viewVariantsModule = new DevExpress.ExpressApp.ViewVariantsModule.ViewVariantsModule();
			this.workflowModule = new DevExpress.ExpressApp.Workflow.WorkflowModule();
			((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
			// 
			// securityStrategyComplex1
			// 
			this.securityStrategyComplex1.Authentication = this.authenticationStandard1;
			this.securityStrategyComplex1.RoleType = typeof(aztall.Module.BusinessObjects.Role);
			this.securityStrategyComplex1.UserType = typeof(aztall.Module.BusinessObjects.User);
			// 
			// authenticationStandard1
			// 
			this.authenticationStandard1.LogonParametersType = typeof(DevExpress.ExpressApp.Security.AuthenticationStandardLogonParameters);
			// 
			// auditTrailModule
			// 
			this.auditTrailModule.AuditDataItemPersistentType = typeof(DevExpress.Persistent.BaseImpl.AuditDataItemPersistent);
			// 
			// notificationsModule
			// 
			this.notificationsModule.CanAccessPostponedItems = false;
			this.notificationsModule.NotificationsRefreshInterval = System.TimeSpan.Parse("00:05:00");
			this.notificationsModule.NotificationsStartDelay = System.TimeSpan.Parse("00:00:05");
			this.notificationsModule.ShowNotificationsWindow = true;
			// 
			// pivotChartModuleBase
			// 
			this.pivotChartModuleBase.DataAccessMode = DevExpress.ExpressApp.CollectionSourceDataAccessMode.Client;
			this.pivotChartModuleBase.ShowAdditionalNavigation = false;
			// 
			// reportsModuleV2
			// 
			this.reportsModuleV2.EnableInplaceReports = true;
			this.reportsModuleV2.ReportDataType = typeof(DevExpress.Persistent.BaseImpl.ReportDataV2);
			this.reportsModuleV2.ReportStoreMode = DevExpress.ExpressApp.ReportsV2.ReportStoreModes.XML;
			// 
			// reportsAspNetModuleV2
			// 
			this.reportsAspNetModuleV2.ReportViewerType = DevExpress.ExpressApp.ReportsV2.Web.ReportViewerTypes.HTML5;
			// 
			// stateMachineModule
			// 
			this.stateMachineModule.StateMachineStorageType = typeof(DevExpress.ExpressApp.StateMachine.Xpo.XpoStateMachine);
			// 
			// validationModule
			// 
			this.validationModule.AllowValidationDetailsAccess = true;
			this.validationModule.IgnoreWarningAndInformationRules = false;
			// 
			// workflowModule
			// 
			this.workflowModule.RunningWorkflowInstanceInfoType = typeof(DevExpress.ExpressApp.Workflow.Xpo.XpoRunningWorkflowInstanceInfo);
			this.workflowModule.StartWorkflowRequestType = typeof(DevExpress.ExpressApp.Workflow.Xpo.XpoStartWorkflowRequest);
			this.workflowModule.UserActivityVersionType = typeof(DevExpress.ExpressApp.Workflow.Versioning.XpoUserActivityVersion);
			this.workflowModule.WorkflowControlCommandRequestType = typeof(DevExpress.ExpressApp.Workflow.Xpo.XpoWorkflowInstanceControlCommandRequest);
			this.workflowModule.WorkflowDefinitionType = typeof(DevExpress.ExpressApp.Workflow.Xpo.XpoWorkflowDefinition);
			this.workflowModule.WorkflowInstanceKeyType = typeof(DevExpress.Workflow.Xpo.XpoInstanceKey);
			this.workflowModule.WorkflowInstanceType = typeof(DevExpress.Workflow.Xpo.XpoWorkflowInstance);
			// 
			// aztallAspNetApplication
			// 
			this.ApplicationName = "aztall";
			this.CheckCompatibilityType = DevExpress.ExpressApp.CheckCompatibilityType.DatabaseSchema;
			this.Modules.Add(this.module1);
			this.Modules.Add(this.module2);
			this.Modules.Add(this.auditTrailModule);
			this.Modules.Add(this.objectsModule);
			this.Modules.Add(this.chartModule);
			this.Modules.Add(this.cloneObjectModule);
			this.Modules.Add(this.conditionalAppearanceModule);
			this.Modules.Add(this.validationModule);
			this.Modules.Add(this.kpiModule);
			this.Modules.Add(this.notificationsModule);
			this.Modules.Add(this.pivotChartModuleBase);
			this.Modules.Add(this.pivotGridModule);
			this.Modules.Add(this.reportsModuleV2);
			this.Modules.Add(this.schedulerModuleBase);
			this.Modules.Add(this.stateMachineModule);
			this.Modules.Add(this.treeListEditorsModuleBase);
			this.Modules.Add(this.viewVariantsModule);
			this.Modules.Add(this.workflowModule);
			this.Modules.Add(this.module3);
			this.Modules.Add(this.chartAspNetModule);
			this.Modules.Add(this.fileAttachmentsAspNetModule);
			this.Modules.Add(this.notificationsAspNetModule);
			this.Modules.Add(this.pivotChartAspNetModule);
			this.Modules.Add(this.pivotGridAspNetModule);
			this.Modules.Add(this.reportsAspNetModuleV2);
			this.Modules.Add(this.schedulerAspNetModule);
			this.Modules.Add(this.treeListEditorsAspNetModule);
			this.Modules.Add(this.validationAspNetModule);
			this.Modules.Add(this.module4);
			this.Modules.Add(this.securityModule1);
			this.Security = this.securityStrategyComplex1;
			this.DatabaseVersionMismatch += new System.EventHandler<DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs>(this.aztallAspNetApplication_DatabaseVersionMismatch);
			((System.ComponentModel.ISupportInitialize)(this)).EndInit();

        }
    }
}
